//
//  UIView+Manager.m
//  RDDManager
//
//  Created by 谢帆 on 2017/10/10.
//  Copyright © 2017年 谢帆. All rights reserved.
//

#import "UIView+Manager.h"

typedef NS_ENUM(NSInteger , FrameType) {
    FrameTypeX = 0,
    FrameTypeY,
    FrameTypeWidth,
    FrameTypeHeight,
};

@implementation UIView (Manager)

#pragma mark - frame

- (CGFloat)maxY{
    return CGRectGetMaxY(self.frame);
}

- (CGFloat)maxX{
    return CGRectGetMaxX(self.frame);
}

- (CGFloat)x{
    return self.frame.origin.x;
}

- (CGFloat)y{
    return self.frame.origin.y;
}

- (CGFloat)width{
    return self.frame.size.width;
}

- (CGFloat)height{
    return self.frame.size.height;
}

- (CGSize)size{
    return self.frame.size;
}

- (CGPoint)origin{
    return self.frame.origin;
}

- (void)changeY:(CGFloat)y
{
    [self changeFrameWithKey:FrameTypeY andParam:y];
}

- (void)changeX:(CGFloat)x{
    [self changeFrameWithKey:FrameTypeX andParam:x];
    
}

- (void)changeWidth:(CGFloat)width{
    [self changeFrameWithKey:FrameTypeWidth andParam:width];
    
    
}

- (void)changeHeight:(CGFloat)height{
    [self changeFrameWithKey:FrameTypeHeight andParam:height];
    
}

- (void)changeFrameWithKey:(FrameType)type andParam:(CGFloat)param{
    
    CGRect frame = self.frame;
    
    if (param == NAN) {
        return;
    }
    
    switch (type) {
        case FrameTypeX:
            frame.origin.x = param;
            break;
        case FrameTypeY:
            frame.origin.y = param;
            break;
        case FrameTypeWidth:
            frame.size.width = param;
            break;
        case FrameTypeHeight:
            frame.size.height = param;
            break;
            
        default:
            break;
    }
    
    self.frame = frame;
}

#pragma mark - 换大小,不换位置
- (void)changeSize:(CGSize)size{
    CGPoint center = self.center;
    
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
    
    self.center = center;
}

#pragma mark - 换大小，换位置
- (void)changeSizeFitOrigin:(CGSize)size{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

#pragma mark - 换位置，大小不变
- (void)changeOrigin:(CGPoint)origin{
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}


#pragma  ====== layer

- (void)layerWithRadian:(CGFloat)radian{
    
    self.layer.cornerRadius = radian;
    self.layer.masksToBounds = YES;
    
}

- (void)lineViewShowWithFrame:(CGRect)frame{
    
    [self lineViewShowWithFrame:frame andLineColor:[UIColor red:238 green:238 blue:238]];
}

- (void)lineViewShowWithFrame:(CGRect)frame andLineColor:(UIColor*)color{
    CALayer* layer = [CALayer layer];
    
    layer.backgroundColor = color.CGColor;
    
    layer.frame = frame;
    
    [self.layer addSublayer:layer];
}


@end
